package com.easyedu.student.service;

import com.easyedu.core.entity.po.OpenCourse;
import com.easyedu.core.entity.po.StudentSelect;
import com.easyedu.core.exception.EasyEduException;
import com.easyedu.student.dao.CourseDao;
import com.easyedu.student.dao.StudentSelectDao;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author lmr
 **/
@Service
public class CourseService {

    private final CourseDao courseDao;

    private final StudentSelectDao studentSelectDao;

    public CourseService(CourseDao courseDao, StudentSelectDao studentSelectDao) {
        this.courseDao = courseDao;
        this.studentSelectDao = studentSelectDao;
    }

    public List<OpenCourse> getOptionalCourse(Integer openYear, Long instituteId, Long departmentId, String schoolYear,
                                              String semester) {
        List<OpenCourse> optionalCourse = courseDao.getOptionalCourse(openYear, instituteId, departmentId, schoolYear,
                semester);
        if (optionalCourse.isEmpty()) {
            throw new EasyEduException(1999, "没有可选课程");
        }
        return optionalCourse;
    }

    public List<StudentSelect> getHasSelectCourse(Long instituteId, Long departmentId, Integer openYear, String schoolYear,
                                                  String semester, Long studentNumber) {
        List<StudentSelect> hasSelectCourse = studentSelectDao.getHasSelectCourse(instituteId, departmentId, openYear,
                schoolYear, semester, studentNumber);
        if (hasSelectCourse.isEmpty()){
            throw new EasyEduException(1999, "没有已选课程");
        }
        return hasSelectCourse;
    }
}
